package oschina.by.isrefluxer.com.weatherapplication;

import android.app.Service;
import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Typeface;
import android.os.IBinder;


import xml.NewAppWidget;

/**
 * 项目名称：WeatherApplication
 * 类描述：
 * 创建人：Administrator
 * 创建时间：2016/10/18 19:06
 * 修改人：Administrator
 * 修改时间：2016/10/18 19:06
 * 修改备注：
 */
public class DateServer extends Service {
    private  Typeface typeFace;
    private Context context;
    private BroadcastReceiver boroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            AppWidgetManager awm =AppWidgetManager.getInstance(context);
            int []appWidgetIds = awm.getAppWidgetIds(new ComponentName(context, NewAppWidget.class));
            NewAppWidget.updateTimeWidget(context,awm,appWidgetIds);
        }
    };



    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        typeFace = Typeface.createFromAsset(getApplicationContext().getAssets(),"DINPro-Light.otf");

        initFilter();

        BitmapsUtil.start(context);
    }

    private void initFilter() {

        IntentFilter intentfilter = new IntentFilter();
        intentfilter.addAction(Intent.ACTION_TIME_TICK); // 时间的流逝
        intentfilter.addAction(Intent.ACTION_TIME_CHANGED); // 时间被改变，人为设置时间
        registerReceiver(boroadcastReceiver, intentfilter);
    }

    @Override
    public void onDestroy() {
        unregisterReceiver(boroadcastReceiver);
        super.onDestroy();
    }
}
